#include "Folding.h"

#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif


Folding::Folding()
{
}

Folding::~Folding()
{
}


void Folding::fold_time_series(const unsigned num_bins,
        const double fold_period,
        const unsigned num_data,
        const double * time, const double * data,
        double * folded_data)
{
    const double fold_freq = 1.0 / fold_period;
    const double bin_inc = 1.0 / (double)num_bins;

    printf("fold period = %f\n", fold_period);
    printf("fold freq   = %f\n", fold_freq);
    printf("num bins    = %i\n", num_bins);
    printf("bin inc     = %f\n", bin_inc);

    // Convert data times to phase.
    vector<double> phase(num_data, 0.0);

    // Evaluate phase for each time based on fold period.
    for (unsigned i = 0; i < num_data; ++i)
    {
        double fract_phase = time[i] / fold_period;
        phase[i] = fract_phase - int(fract_phase);
//        printf("%i %f %f\n",i, time[i], phase[i]);
    }

    // Sum into bins
    for (unsigned i = 0; i < num_data; ++i)
    {
    }

//    memcpy(folded_data, &phase[0], num_data * sizeof(double));
}
